<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<#include "../common/head.ftl">
<style>
    #EditEntity {
        overflow-y: auto !important;
    }
</style>

<body class="gray-bg">
<#include "../common/modal.ftl">

<#include "../common/delete.ftl">

<#include "../common/entity.ftl">

<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-content" id="search">
                    <div class="search-box">
                        用户名：
                        <div><input type="search" name="username"></div>
                        部门：
                        <div><input type="search" name="department"></div>
                        工号：
                        <div><input type="search" name="workNumber"></div>
                        <button class='btn btn-search'>搜索</button>
                    </div>
                    <div class='hr'></div>
                    <div class='top_row'>
                        <button type="button" id="add" class="btn btn-default btn-success"
                                style="color: #fff;background-color: #398439; border-color: #255625;">添加会议参与人
                        </button>
                        <div class="pull-right page">
                            每页显示:<span class='page_active'>10</span><span>20</span><span>30</span><span>40</span><span>50</span>
                        </div>
                    </div>
                    <table class="table table-striped table-bordered table-hover dataTables-example">
                        <thead>
                        <tr>
                            <th name="id" style="display:none;">id</th>
                            <th name="username">用户名</th>
                            <th name="department">部门</th>
                            <th name="workNumber">工号</th>
                            <th name="phone">手机号</th>
                            <th name="email">邮箱</th>
                            <th name="">功能选项</th>
                        </tr>
                        </thead>
                        <tbody></tbody>
                    </table>
                    <div class="paging"></div>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="${basePath}/js/jquery.min.js?v=2.1.4"></script>
<script src="${basePath}/js/page.js"></script>
<script src="${basePath}/js/common.js"></script>
<script src="${basePath}/js/bootstrap.min.js?v=3.3.6"></script>

<script type="text/javascript">
    var reader = new FileReader();
    var table = initTable("${basePath}/function/findParticipateList", "search", $("table"), "paging");
    EditEntity("编辑会议参与人", "添加会议参与人", $("table"), $("#add"),
            "${basePath}/function/participateForm",
            null, null, "${basePath}/function/deleteParticipateById",
            table.search);
    $("table").on("click", "tbody tr td a:first-child", function () {
        var id = $(this).parents("tr").find("td:first").text();
        $('#EditEntity').modal("show").find(".modal-title").text("编辑会议参与人");
        $('#EditEntity').find('[onlyread]').prop("disabled", true);
        $('#EditEntity').find('[updateonlyread]').prop("disabled", true);
        $('#EditEntity').find('[addonlyread]').prop("disabled", false);
        AsyncGet("${basePath}/function/findParticipateById", {id: id}, function (value) {
            $('#EditEntity').find("form [name]").each(function () {
                $(this).val(value[$(this).attr("name")]);
            })
            $('#EditEntity').find("form img").attr("src", "${basePath}/function/getAvatar?avatar=" + value.avatar).show();
        })
    })
    $("#add").click(function () {
        $('#EditEntity').find("form img").hide().attr("src", "");
    })
    $('#EditEntity').on("change", "[name='file']", function () {
        $(this).prev().val($(this).val());
        reader.readAsDataURL(this.files[0]);
    });
    reader.onload = function (e) {
        $('#EditEntity').find("form img").attr("src", e.target.result).show();
    }
    $('#EditEntity').find(".modal-footer button:last").click(function () {
        var formData = getFileFormData($('#EditEntity').find("form"));
        $.ajax({
            url: "${basePath}/function/updateParticipate",
            type: 'POST',
            data: formData,
            async: false,
            cache: false,
            contentType: false,
            processData: false,
            success: function (value) {
                if (value.code == 0) {
                    ShowMessage(value.msg);
                    $('#EditEntity').modal("hide");
                    table.search();
                } else {
                    ErrMessage(value.msg);
                }
            }
        });
    });

</script>

</body>
</html>